<?php
class Gallery_Model_DbTable_Image_Row extends Zend_Db_Table_Row_Abstract {
	protected function _insert() {
		if (isset($this->image)) {
			$this->_setWidthHeightParams();
		}
	}

	protected function _update() {
		if (isset($this->image)) {
			if ($this->image == '') {
				unset($this->image);
			} else {
				$this->_setWidthHeightParams();
			}
		}
	}

	/**
	 * Ustawienie szerokości i wysokości grafiki
	 * @return void
	 */
	protected function _setWidthHeightParams() {
		$path = Gallery_Model_Image::UPLOAD_PATH . DIRECTORY_SEPARATOR;
		$path .= $this->image;
		if (is_readable($path)) {
			list($width, $height, $type, $attr) = getimagesize($path);
			$this->width = $width;
			$this->height = $height;
		}
	}

	protected function _delete() {
		if (isset($this->image)) {
			$path = Gallery_Model_Image::UPLOAD_PATH . DIRECTORY_SEPARATOR . $this->image;
			if (is_file($path)) {
				@unlink($path);
			}
		}
	}
}